<template>
  <div>
    <ul v-for="(v, k) in x" :key="'prime' + k">
      <li>{{v}}: {{y1[k]}} ======= {{y2[k]}}</li>
    </ul>
  </div>
</template>

<script>
import _ from "lodash";
function prime(n) {
  for (let i = 2; i <= Math.sqrt(n); i++) {
    if (n % i == 0) {
      return 0;
    }
  }
  return 1;
}

function fermatTest(n) {
  let a = _.shuffle(_.range(2, n)).slice(0, 20);
  let succ = 0;
  for (let i = 0; i < a.length; i++) {
    if (Math.pow(a[i], n - 1) % n == 1 % n) {
      succ++;
    }
    // console.log(n, ":", a[i], Math.pow(a[i], n - 1) % n, 1 % n, succ);
  }
  return succ / a.length;
}
export default {
  name: "Fermat",
  data () {
    return {
      x: [],
      y1: [],
      y2: [],
    };
  },
  mounted () {
    for (let i = 23; i < 200; i+=2) {
      this.x.push(i);
      this.y1.push(prime(i));
      this.y2.push(fermatTest(i));
    }
  }
}
</script>

<style scoped>

</style>